<%@page import="com.xnx3.wangmarket.admin.entity.Site"%>
<%@page import="com.xnx3.j2ee.Global"%>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>  
<%@ taglib uri="http://www.xnx3.com/java_xnx3/xnx3_tld" prefix="x" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<jsp:include page="../../../../iw/common/head.jsp">
	<jsp:param name="title" value="部门列表"/>
</jsp:include>

<!-- 列表数据 -->
<table class="layui-table" style="margin:0px;">
    <thead>
        <tr>
            <th>编号id</th>
            <th>部门名称</th>
            <th>操作</th>
        </tr>
    </thead>
    <tbody>
        <c:forEach items="${list}" var="item">
            <tr>
                <td>${item['id'] }</td>
                <td>${item['name'] }</td>
                <td>
                	<botton class="layui-btn layui-btn-sm" onclick="branch('${item['id'] }', '${item['name'] }');">编辑</botton>
                	<botton class="layui-btn layui-btn-sm" onclick="deleteBranch('${item['id'] }', '${item['name'] }');">删除</botton>
				</td>
            </tr>
        </c:forEach>
    </tbody>
</table>
<!-- 通用分页跳转 -->
<jsp:include page="../../../../iw/common/page.jsp"></jsp:include>

<div style="padding:15px;">
	<button class="layui-btn" onclick="branch(0,'添加');" style="margin-left: 10px;margin-bottom: 20px;"><i class="layui-icon" style="padding-right:8px; font-size: 22px;">&#xe608;</i>添加部门</button>
</div> 

<script>
function branch(id, name){
	layer.open({
		type: 2, 
		//title: false,
		closeBtn: 1,
		title: id>0 ? '编辑部门':'新增部门',
		area: ['460px', '170px'],
		shadeClose: true, //开启遮罩关闭
		content: 'branch.do?id='+id,
		closeBtn: 1
	});
}

/**
 * 删除部门
 * @param id 要删除的部门的id
 * @param name 要删除的部门的名字
 */
function deleteBranch(id, name){
	var dtv_confirm = layer.confirm('确定要删除“'+name+'”吗? ', {
	  btn: ['删除','取消'] //按钮
	}, function(){
		layer.close(dtv_confirm);
		parent.iw.loading('删除中');
		
		$.post("delete.do?id="+id, function(data){
			parent.iw.loadClose();
			if(data.result == '1'){
				parent.iw.msgSuccess("删除成功");
				location.reload();
	     	}else if(data.result == '0'){
	     		parent.iw.msgFailure(data.info);
	     	}else{
	     		parent.iw.msgFailure();
	     	}
		});
		
	}, function(){
	});
}
</script>
 
<jsp:include page="../../../../iw/common/foot.jsp"></jsp:include>
</body>
</html>